package xyz.zq.sf.auth.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;

/**
 * 认证失败处理器
 *
 * @author hzq
 * @date 2021-02-07 15:20
 */
@Slf4j
@Component
public class SfAuthenticationFailureEventHandler implements ApplicationListener<AbstractAuthenticationFailureEvent> {

    @Override
    public void onApplicationEvent(AbstractAuthenticationFailureEvent event) {
        Authentication authentication = (Authentication) event.getSource();
        AuthenticationException exception = event.getException();
        log.info("用户：{}，登录失败，异常：{}", authentication.getPrincipal(), exception.getMessage());
    }
}
